/*
 *  $Id: GhostlyWinds.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Spells {
    public class GhostlyWinds: SpellCard {
        public GhostlyWinds(): base("001_a_s_ghostly_winds") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Air;
            Value = 100;
            AddManaCost(ElementType.Air, 4);
            AddCondition(new DelegateCondition(GetConditionPhrase(), HasTargets));
        }

        private static bool HasTargets(AbstractObject caster, Card card) {
            foreach (Creature cr in caster.Owner.GetCreatures())
                if (cr.Card.Element == ElementType.Air)
                    return true;
            return false;
        }

        public override void DoAction(TargetArgs args) {
            foreach (Creature cr in args.Player.GetCreatures()) {
                if (cr.Card.Element == ElementType.Air) {
                    cr.State = CreatureState.Untapped;
                    cr.AddAffect<GhostlyWindsAffect>();
                }
            }
        }

        private class GhostlyWindsAffect: SpellAffect<GhostlyWinds> {
            private TimeAffect _timer;

            public GhostlyWindsAffect() {
                _timer = new TimeAffect(1, TimePhase.OwnOffence);
                _timer.Add(new Affects.Spirit());
                _timer.Add(new Affects.Berserk());
                Add(_timer);
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override void ResetAffect() {
                base.ResetAffect();
                if (_timer.IsEnded)
                    Owner.Owner.DamageDirectBy(NewDamage(DamageType.MagicAttack, 1), true);
            }
        }
    }
}
